﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ww.wwf.wwfbll;
using ww.lis.lisbll.sam;
using System.Collections;
using System.IO;

namespace ww.form.lis.sam.jy
{
    public partial class YbfwForm : ww.form.wwf.SysBaseForm
    {
        string str_type = "";//业务类型
        string str_ybyq = "";//仪器类型
        string str_ybrq = "";//样本日期
        string str_shr = "";//审核人

        public YbfwForm(string type,string ybyq,string ybrq,string shr)
        {
            InitializeComponent();
            str_type = type;
            str_ybyq = ybyq;
            str_ybrq = ybrq;
            str_shr = shr;
        }

        private void buttonTC_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button确定_Click(object sender, EventArgs e)
        {
            string fsample_code = txt_ybfw.Text.Trim();

            if (fsample_code == "" || !fsample_code.Contains("-"))
            {
                WWMessage.MessageShowError("样本范围有误，请检查！");
                this.ActiveControl = txt_ybfw;
                return;
            }

            string[] code = fsample_code.Split('-');

            int begin, end;
            begin = Convert.ToInt32(code[0]);
            end = Convert.ToInt32(code[1]);
            if (end < begin)
            {
                WWMessage.MessageShowError("样本范围有误，请检查！");
                this.ActiveControl = txt_ybfw;
                return;
            }

            txt_ybfw.Text = begin.ToString("000") + "-" + end.ToString("000");

            if (str_type == "sh")
            {
                WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "exec Lis_Ins_Result_CheckMult '" + str_ybyq + "','" + str_ybrq + "','" + begin + "','" + end + "','" + str_shr + "'");
                this.DialogResult = DialogResult.OK;
            }
            //if (str_type == "qxsh")
            //{

            //}
            if (str_type == "dy")
            {
                DataTable dt_sam_jy = WWFInit.wwfRemotingDao.DbExecuteDataTableBySqlString(WWFInit.strDBConn, "exec Lis_Ins_Result_PrintMult '" + str_ybyq + "','" + str_ybrq + "','" + begin + "','" + end + "'");
                foreach (DataRow row in dt_sam_jy.Rows)
                {
                    string fjy_id = row["fjy_id"].ToString();
                    ww.form.lis.sam.Report.JyPrint pr = new ww.form.lis.sam.Report.JyPrint();
                    pr.BllPrintViewer(0, fjy_id);
                }
                this.DialogResult = DialogResult.OK;
            }
            //if (str_type == "sc")
            //{

            //}
        }

        private void YbfwForm_Load(object sender, EventArgs e)
        {
            if (str_type == "sh") lbl_caption.Text = "样本批量审核";
            //if (str_type == "qxsh") lbl_caption.Text = "样本批量取消审核";
            if (str_type == "dy") lbl_caption.Text = "样本批量打印";
            //if (str_type == "sc") lbl_caption.Text = "样本批量删除";

            txt_jyyq.Text = WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "select fname from SAM_INSTR where finstr_id='" + str_ybyq + "'");
            txt_ybrq.Text = str_ybrq;
        }

        private void txt_ybfw_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                this.ActiveControl = button确定;
        }

        private void txt_ybfw_Leave(object sender, EventArgs e)
        {

        }
    }
}